home *** CD-ROM | disk | FTP | other *** search
/ Light ROM 1 / LIGHT-ROM 1 (Amiga Library Services)(1994).iso / ffdisks / d897.lha / EPP / PModules / commandLineArgs.e < prev    next >
Text File  |  1993-06-26  |  1KB  |  42 lines

  1. OPT TURBO
  2.  
  3. PMODULE 'PMODULES:cSkipWhite'
  4. PMODULE 'PMODULES:cSkipNonWhite'
  5.  
  6. PROC getArg (theArg,  /* PTR TO STRING       */
  7.              index)   /* Argument id, 1 .. n */
  8.   DEF startPos : PTR TO CHAR, numChars, i, length
  9.  
  10.   /* This routine is intended for KS1.3 programmers who don't have access */
  11.   /* to taglists.  To get the first command-line argument pass in a       */
  12.   /* string large enough to hold arg (s := String (StrLen (arg)) ), and   */
  13.   /* a long int where 1 = first argument, 2 = second argument...  If      */
  14.   /* the requested argument doesn't exist (3 is requested when only 2     */
  15.   /* were entered on the command line) the function returns -1.  This     */
  16.   /* function does not recognize quoted arguments with embedded spaces.   */
  17.  
  18.   IF arg [] <= 0
  19.     StrCopy (theArg, '', ALL)
  20.     RETURN FALSE
  21.   ENDIF
  22.  
  23.   length := StrLen (arg)
  24.   startPos := arg
  25.  
  26.   FOR i := 2 TO index
  27.     startPos := cSkipNonWhite (startPos)  /* Find next space. */
  28.     startPos := cSkipWhite (startPos)     /* Find start of next arg. */
  29.     IF (startPos [] = 0)
  30.       /* End of string encountered before requested arg. */
  31.       StrCopy (theArg, '', ALL)
  32.       RETURN FALSE
  33.     ENDIF
  34.   ENDFOR
  35.  
  36.   numChars := (cSkipNonWhite (startPos) - startPos)   /* Find end of arg. */
  37.   MidStr (theArg, startPos, 0, numChars)
  38.  
  39. ENDPROC  TRUE
  40.   /* getArg */
  41.  
  42.